// pages/catogerySelect/catogerySelect.js
var httpClient = require('../../utils/httpClient.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        relations: [],
        currentParentIndex:0,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.queryCatogery();
    },
    searchInput: function (e) {
        var detail = e.detail;
    },
    queryCatogery: function () {
        var page = this;
        var storge = wx.getStorageSync("catogeryRelations");
        if(!storge){
            httpClient.get("/catogery/getAll", function (result) {
                wx.setStorageSync("catogeryRelations",result);
                page.setData({
                    relations:result
                })
            });
        }else{
            page.setData({
                relations:storge
            })
        }
    },
    changeParentStyle:function (e) {
        this.setData({
            currentParentIndex:e.currentTarget.dataset.index
        })
    },
    chooseCatogery:function (e) {
        var pages = getCurrentPages();//当前页面
        var prevPage = pages[pages.length-2];//上一页面
        prevPage.setData({//直接给上移页面赋值
            chooseCatogery: e.currentTarget.dataset.item
        });
        wx.navigateBack({//返回
            delta:1
        })
    }
})